package com.windgo.controller.wx;

import com.windgo.bean.bo.WxCollectBo;
import com.windgo.bean.MarketCollect;
import com.windgo.bean.common.BaseRespVo;
import com.windgo.bean.common.CommonData;
import com.windgo.service.CollectService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.PrincipalCollection;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wuwen
 * @since 2022/10/15
 * 09:44
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    CollectService collectService;
    @RequestMapping("list")
    //http://182.92.235.201:8083/wx/collect/list?type=0&page=2&limit=10
    public BaseRespVo list(Byte type,Integer page,Integer limit){
        CommonData<WxCollectBo> data = collectService.WxCollect(type, page, limit);
        return BaseRespVo.ok(data);
    }
    @PostMapping("addordelete")
    //http://182.92.235.201:8083/wx/collect/addordelete
    public BaseRespVo addordelete(@RequestBody MarketCollect marketCollect){
        Subject subject = SecurityUtils.getSubject();
        PrincipalCollection principals = subject.getPrincipals();
        if(principals==null){
          return BaseRespVo.ok2();
        }
        Integer valueId = marketCollect.getValueId();
        Integer i = collectService.WxCollectDelete(valueId);
        if(i!=1){
            return null;
        }
        return BaseRespVo.ok();
    }
}

